﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Shared/default.master" AutoEventWireup="true" CodeFile="MyAddressList.aspx.cs" Inherits="Pages_Usercenter_MyAddressList" %>

<%@ Register src="../../Misc/Control/MyAccount.ascx" tagname="MyAccount" tagprefix="uc1" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">

<script type="text/javascript" src="../../JS/jquery.js"></script>
<script type="text/javascript">
<!--//--><![CDATA[//><!--

    //更改默认地址  
    function updateaddress(id,uid){
		  //var area_id = $("#qu").val();
          $.post("/ucenter/default/address/change/"+id+"/"+uid, function(data){
		   if(data){
				 alert("修改成功");
		   }else{
		         alert("修改失败，用户id不匹配");
		   }
          });
          setTimeout('myrefresh()',2000); //指定2秒后刷新
    }
//刷新页面
function myrefresh()
{
       window.location.reload();
}
//添加地址
function newaddress(){

  $("#newaddress").html("");
  $("#newaddress").html("<ul class=\"dingd_gray\"><li class=\"dingd_13\"><div><em>收 货 人：</em><input type=\"text\"  class=\"index_input6\" id=\"nr_name\"/></div><div><em>收货地址：</em><input type=\"text\"  class=\"index_input6\" id=\"nr_address\"/></div><div><em>邮　　编：</em><input type=\"text\"  class=\"index_input6\" id=\"nr_zip\"/></div><div><em>手　　机：</em><input type=\"text\"  class=\"index_input6\" id=\"nr_mobile\"/></div></li><li class=\"dingd_14\"><em></em></li><li class=\"dingd_15\"><em onclick=\"submitaddress();\" style=\"cursor:pointer\">确定</em></li></ul>");
  $("#add").html("");
  $("#add").html("<input type=\"button\" class=\"index_but6\" value=\"添加新地址\" />");
}

function submitaddress(){
  var nr_name = encodeURI($("#nr_name").val());
  var nr_address = encodeURI($("#nr_address").val());
  var nr_zip = $("#nr_zip").val();
  var nr_mobile = $("#nr_mobile").val();    
  if(nr_name==""||nr_mobile==""){
                 alert("姓名和手机为必填项！");    
  }else{
          $.post("/ucenter/address/new/"+nr_name+"/"+nr_address+"/"+nr_zip+"/"+nr_mobile, function(data){
		   if(data){
				 alert("添加成功");
			
		   }else{
		         alert("最多可添加三个地址");
		   }
        });
          setTimeout('myrefresh()',2000); //指定2秒后刷新 
  }
}
    //删除
    function deleteaddress(id,uid){
      if (!confirm("确定要删除吗？删除将不可恢复")){ 
						 return false;
	  }else{
          $.post("/ucenter/default/address/delete/"+id+"/"+uid, function(data){
           if(data){
				 alert("删除成功");
		   }else{
		         alert("删除失败，用户id不匹配");
		   }
  
          });
          setTimeout('myrefresh()',2000); //指定2秒后刷新
      }   
    }
    //按id获取
    function byidaddress(id,uid){
          $.post("/ucenter/default/address/byid/"+id+"/"+uid, function(data){
		   if(data){
              $("#address"+id).html("");
              //$("#address"+id).hide();
              $("#address"+id).html(data);
		   } 
          });
    }
    //更新
    function updatebyidaddress(id,uid){
    
  var nr_name = encodeURI($("#nr_name"+id).val());
  if($("#nr_address"+id).val()==""){
  var nr_address = "undefined";
  }else{
  var nr_address = encodeURI($("#nr_address"+id).val());
  }
  if($("#nr_zip"+id).val()==""){
  var nr_zip = 0;
  }else{
  var nr_zip = encodeURI($("#nr_zip"+id).val());
  }
  var nr_mobile = $("#nr_mobile"+id).val();

          $.post("/ucenter/address/update/"+nr_name+"/"+nr_address+"/"+nr_zip+"/"+nr_mobile+"/"+id+"/"+uid, function(data){
           if(data){
				 alert("更新成功");
		   }else{
		         alert("更新失败，用户id不匹配");
		   }
  
          });
          setTimeout('myrefresh()',2000); //指定2秒后刷新
    }
    
//--><!]]>
</script>

<title>用户收货地址</title>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<div class="main2"> 
 <div class="main_l">              
  <!--左侧部分 开始-->
		<div class="dingd_top">
		<asp:ObjectDataSource ID="odsAddressList" runat="server" 
        OldValuesParameterFormatString="original_{0}" SelectMethod="GetModelListByEmail" 
        TypeName="Tuan.BLL.AddressInfo">
        <SelectParameters>
            <asp:ControlParameter ControlID="hdUserName" DefaultValue="" Name="email" 
                PropertyName="Value" Type="String" />
        </SelectParameters>
    </asp:ObjectDataSource>
			<ul>
				<li class="navon"><a href="MyOrderList.aspx"><span>我的订单</span></a></li>
				<li class="navon"><a href="MyEventList.aspx"><span>我的活动</span></a></li>
				<li><a href="MyAddressList.aspx"><span>地址簿</span></a></li>
				<li class="navon"><a href="MyReviewList.aspx"><span>我的留言</span></a></li>
			</ul>
		</div>
		<div class="l_area3">	
			<div class="blank25"></div>
			<div class="dingd2">
			<pan:SmartGridView ID="panGdvOrderList" runat="server" 
                AutoGenerateColumns="False" DataSourceID="odsAddressList" AllowPaging="True" >
                <Columns>
                <asp:TemplateField>
                <ItemTemplate >
				<ul class="dingd_gray" id="address2723">
					<li class="dingd_13">
						<div><em>收 货 人：</em><%#Eval("Signer") %></div>
						<div><em>收货地址：</em><%#Eval("Address") %></div>
						<div><em>邮　　编：</em><%#Eval("Zip") %></div>
						<div><em>手　　机：</em><%#Eval("Tel") %></div>
					</li>
										<li class="dingd_14"><em>默认地址</em></li>
										<li class="dingd_14"><em style="cursor:pointer" onclick="updateaddress('<%#Eval("AddressID") %>','<%#Eval("UserID") %>')>设为默认地址</em></li>
										<li class="dingd_15"><em style="cursor:pointer" onclick="byidaddress('<%#Eval("AddressID") %>','<%#Eval("UserID") %>')">修改</em><em style="cursor:pointer" onclick="deleteaddress('<%#Eval("AddressID") %>','<%#Eval("UserID") %>')">删除</em></li>
				</ul>
				
									</ItemTemplate>
                
				</asp:TemplateField>
                
                </Columns>
                </pan:SmartGridView>
							
		
                <div  id="newaddress"> 
                      <!-- 动态装入 -->
                </div>		
			</div>
			<div class="blank25"></div>
			<%--<div    class="dingd_center" id="add"><input name="" type="button" class="index_but4" value="添加新地址" onclick="newaddress();"/></div>--%>
			<div class="dingd_center"></div>
			<div class="blank25"></div>
		</div>
		<div class="l_bot">
            
     </div>
	<!--左侧部分 结束--> </div> 
  	<uc1:MyAccount ID="MyAccount1" runat="server" />
          
    
	<DIV class="go-top"><A href="#uptop">↑顶部</A></DIV></div>
	<asp:HiddenField   ID="hdUserName" runat="server" />
</asp:Content>

